package com.hunan.api.catv.action.collect;

import com.hunan.api.catv.action.BaseAction;
import com.hunan.api.catv.annotation.MemberAuth;
import com.hunan.api.catv.common.Api;
import com.hunan.api.catv.entity.Result;
import com.hunan.api.catv.service.biz.collect.CollectBiz;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping(Api.collect)
public class CollectAction extends BaseAction {
    @Autowired
    CollectBiz collectBiz;

    @MemberAuth
    @PostMapping("/submit")
    public Result submit(HttpServletRequest request, String itemId, Integer contentType, Integer collectType) {
        if (ObjectUtils.isEmpty(itemId)) {
            return buildRequire("itemId require");
        }
        if (ObjectUtils.isEmpty(contentType)) {
            return buildRequire("contentType require");
        }
        if (ObjectUtils.isEmpty(collectType)) {
            return buildRequire("collectType require");
        }
        return buildResult(collectBiz.submit(getMemberId(request), itemId, contentType, collectType));
    }

    @MemberAuth
    @GetMapping("/list")
    public Result list(Integer pageNum, HttpServletRequest requestSize, HttpServletRequest request, Integer contentType) {
        return buildOK(collectBiz.list(pageNum, getPageSize(requestSize), getMemberId(request), contentType), "");
    }

    @MemberAuth
    @GetMapping("/status")
    public Result ststus(Integer itemId, Integer contentType, HttpServletRequest request) {
        return buildOK(collectBiz.status(getMemberId(request), itemId, contentType), "");
    }
}
